package com.tencent.wxcloudrun.controller;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tencent.wxcloudrun.config.ApiResponse;
import com.tencent.wxcloudrun.manager.UserManager;
import com.tencent.wxcloudrun.vo.request.user.*;
import com.tencent.wxcloudrun.vo.response.user.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author ZhaoZiYin
 * @Date 2025/2/20
 * @Description 用户控制器
 */
@Api(tags = "用户控制器")
@Slf4j
@RestController
@Validated
@RequestMapping("/api/user")
public class UserController {

    @Resource
    private UserManager userManager;

    @ApiOperation("用户查询")
    @PostMapping(value = "/query")
    public ApiResponse<UserQueryResVo> query(@RequestBody @Valid UserQueryReqVo reqVo) {
        return ApiResponse.ok(userManager.query(reqVo));
    }

    @ApiOperation("用户新增")
    @PostMapping(value = "/add")
    public ApiResponse<UserAddResVo> add(@RequestBody @Valid UserAddReqVo reqVo) {
        return ApiResponse.ok(userManager.add(reqVo));
    }

    @ApiOperation("用户更新")
    @PostMapping(value = "/update")
    public ApiResponse<UserUpdateResVo> update(@RequestBody @Valid UserUpdateReqVo reqVo) {
        return ApiResponse.ok(userManager.update(reqVo));
    }

    @ApiOperation("查询用户收货地址")
    @PostMapping(value = "/address/query")
    public ApiResponse<UserQueryAddressResVo> queryAddress(@RequestBody @Valid UserQueryAddressReqVo reqVo) {
        return ApiResponse.ok(userManager.queryAddress(reqVo));
    }

    @ApiOperation("保存用户收货地址")
    @PostMapping(value = "/address/save")
    public ApiResponse<UserSaveAddressResVo> saveAddress(@RequestBody @Valid UserSaveAddressReqVo reqVo) {
        return ApiResponse.ok(userManager.saveAddress(reqVo));
    }

}
